home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / pibasync.arc / DUMBTRM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-10-31  |  8.0 KB  |  215 lines

  1. (*$C-,U-,R-,V-,K-*)
  2. PROGRAM DumbTrm;
  3.  
  4. (*--------------------------------------------------------------------------*)
  5. (*                                                                          *)
  6. (*   Program:   DumbTrm                                                     *)
  7. (*                                                                          *)
  8. (*   Author:    Philip R. Burns                                             *)
  9. (*                                                                          *)
  10. (*   Date:      November 1, 1986                                            *)
  11. (*                                                                          *)
  12. (*   Purpose:   Dumb terminal emulator to demonstrate PibAsync routines.    *)
  13. (*                                                                          *)
  14. (*   Usage:     Compile to .COM file using Turbo Pascal and execute the     *)
  15. (*              .COM file by typing  DUMBTRM  at the DOS prompt.            *)
  16. (*                                                                          *)
  17. (*              You will be prompted for the required communications        *)
  18. (*              parameters.  If the serial port can be opened successfully, *)
  19. (*              then a dumb terminal mode is entered.                       *)
  20. (*                                                                          *)
  21. (*              To exit dumb terminal mode, type ^C (ascii 03).  To send    *)
  22. (*              a break, type ^B (ascii 02).                                *)
  23. (*                                                                          *)
  24. (*   Needs:     See includes below for files included from PibAsync.Arc.    *)
  25. (*                                                                          *)
  26. (*   Remarks:   This program doesn't check for input mistakes when the      *)
  27. (*              communications parameters are being entered.                *)
  28. (*                                                                          *)
  29. (*--------------------------------------------------------------------------*)
  30.  
  31. (*$I GLOBTYPE.GLO *)
  32. (*$I ASCII.GLO    *)
  33.  
  34. VAR
  35.    Baud_Rate   : INTEGER           (* Baud rate for connection, e.g., 1200  *);
  36.    Com_Port    : INTEGER           (* Which port, e.g., 1 for COM1:         *);
  37.    Parity      : CHAR              (* Parity, e.g., E for even parity       *);
  38.    Data_Bits   : INTEGER           (* How many bits per character, e.g., 8  *);
  39.    Stop_Bits   : INTEGER           (* How many stop bits -- nearly always 1 *);
  40.  
  41. VAR
  42.    InBufSize   : INTEGER           (* Size of input buffer                  *);
  43.    OutBufSize  : INTEGER           (* Size of output buffer                 *);
  44.    Do_XonXoff  : CHAR              (* 'Y' to do XON/XOFF flow control       *);
  45.    Do_HardWired: CHAR              (* 'Y' to do XON/XOFF flow control       *);
  46.    Do_CTS      : CHAR              (* 'Y' to do CTS checking                *);
  47.    Do_DSR      : CHAR              (* 'Y' to do DSR checking                *);
  48.  
  49. (*$I PIBASYNC.GLO *)
  50. (*$I PIBASYN1.MOD *)
  51. (*$I PIBASYN2.MOD *)
  52. (*$I PIBASYN3.MOD *)
  53.  
  54. (*--------------------------------------------------------------------------*)
  55.  
  56. PROCEDURE Get_Comm_Params;
  57.  
  58. VAR
  59.    YesNo : CHAR;
  60.  
  61. BEGIN (* Get_Comm_Params *)
  62.  
  63.    WRITELN;
  64.  
  65.    WRITE('Enter com port (1,2,3,4):                             ');
  66.    READLN( Com_Port );
  67.  
  68.    WRITE('Enter baud rate (300,1200,2400,4800,9600):            ');
  69.    READLN( Baud_Rate );
  70.  
  71.    WRITE('Enter parity (E=even, N=one, O=odd, M=mark, S=space): ');
  72.    READLN( Parity );
  73.  
  74.    Parity := UpCase( Parity );
  75.  
  76.    WRITE('Enter bits per character (7 or 8):                    ');
  77.    READLN( Data_Bits );
  78.  
  79.    WRITE('Enter stop bits (usually 1):                          ');
  80.    READLN( Stop_Bits );
  81.  
  82.    WRITE('Enter size in bytes of async receive buffer:          ');
  83.    READLN( InBufSize );
  84.  
  85.    WRITE('Enter size in bytes of async output buffer:           ');
  86.    READLN( OutBufSize );
  87.  
  88.    WRITE('Use XON/XOFF flow control (Y/N)?                      ');
  89.    READLN( Do_XonXoff );
  90.  
  91.    WRITE('Do CTS checking (Y/N)?                                ');
  92.    READLN( Do_CTS );
  93.  
  94.    WRITE('Do DSR checking (Y/N)?                                ');
  95.    READLN( Do_DSR );
  96.  
  97.    WRITE('Is connection hard-wired (Y/N)?                       ');
  98.    READLN( Do_HardWired );
  99.  
  100. END   (* Get_Comm_Params *);
  101.  
  102. (*--------------------------------------------------------------------------*)
  103.  
  104. FUNCTION Initialize_Communications : BOOLEAN;
  105.  
  106. BEGIN (* Initialize_Communications *)
  107.  
  108.                                    (* Set CTS checking *)
  109.  
  110.    Async_Do_CTS         := ( UpCase( Do_CTS ) = 'Y' );
  111.  
  112.                                    (* Set DSR checking *)
  113.  
  114.    Async_Do_DSR         := ( UpCase( Do_DSR ) = 'Y' );
  115.  
  116.                                    (* Set XON/XOFF to user request *)
  117.  
  118.    Async_Do_XonXoff     := ( UpCase( Do_XonXoff ) = 'Y' );
  119.  
  120.                                    (* Set hard-wired as user requests *)
  121.  
  122.    Async_Hard_Wired_On  := ( UpCase( Do_HardWired ) = 'Y' );
  123.  
  124.                                    (* Set half-second break duration *)
  125.    Async_Break_Length   := 500;
  126.  
  127.                                    (* Let XON/XOFF break points default. *)
  128.  
  129.    Async_Init( InBufSize, OutBufSize, 0, 0, 0);
  130.  
  131.                                    (* Try opening the serial port.   *)
  132.  
  133.    IF ( NOT Async_Open( Com_Port, Baud_Rate, Parity, Data_Bits, Stop_Bits ) ) THEN
  134.       BEGIN
  135.          WRITELN('Cannot open serial port.');
  136.          Initialize_Communications := FALSE;
  137.       END
  138.    ELSE
  139.       BEGIN
  140.          WRITELN('Serial port opened, DumbTrm ready.');
  141.          Initialize_Communications := TRUE;
  142.       END;
  143.  
  144. END   (* Initialize_Communications *);
  145.  
  146. (*--------------------------------------------------------------------------*)
  147.  
  148. PROCEDURE Emulate_Dumb_Terminal;
  149.  
  150. VAR
  151.    Kch: CHAR;
  152.    Ch : CHAR;
  153.  
  154. BEGIN (* Emulate_Dumb_Terminal *)
  155.  
  156.                                    (* Begin loop over serial port   *)
  157.                                    (* and keyboard.                 *)
  158.    REPEAT
  159.                                    (* Pick up and display character *)
  160.                                    (* from port, if any.            *)
  161.  
  162.       IF Async_Receive( Ch ) THEN
  163.          IF ( Ch <> CHR( 0 ) ) THEN
  164.             WRITE( Ch );
  165.                                    (* Read character from keyboard  *)
  166.                                    (* and send out port, unless it  *)
  167.                                    (* is ^B or ^C.                  *)
  168.                                    (*                               *)
  169.                                    (* ^B -- send a break            *)
  170.                                    (* ^C -- quit                    *)
  171.       IF KeyPressed THEN
  172.          BEGIN
  173.             READ( Kbd, KCh );
  174.             CASE KCh OF
  175.                ^B: Async_Send_Break;
  176.                ^C: ;
  177.                ELSE
  178.                   Async_Send( Kch );
  179.             END (* CASE *);
  180.          END;
  181.  
  182.    UNTIL ( Kch = ^C );
  183.  
  184. END   (* Emulate_Dumb_Terminal *);
  185.  
  186. (*--------------------------------------------------------------------------*)
  187.  
  188. PROCEDURE Finish_Communications;
  189.  
  190. BEGIN (* Finish_Communications *)
  191.                                    (* Close port and drop DTR *)
  192.    Async_Close( TRUE );
  193.                                    (* Release space allocated for buffers *)
  194.    Async_Release_Buffers;
  195.  
  196. END   (* Finish_Communications *);
  197.  
  198. (*--------------------------------------------------------------------------*)
  199.  
  200. BEGIN (* DumbTrm *)
  201.  
  202.                                    (* Request serial port parameters     *)
  203.    Get_Comm_Params;
  204.                                    (* Initialize port                    *)
  205.  
  206.    IF Initialize_Communications THEN
  207.       BEGIN
  208.                                    (* Emulate dumb terminal until ^C hit *)
  209.          Emulate_Dumb_Terminal;
  210.                                    (* Close down port                    *)
  211.          Finish_Communications;
  212.  
  213.       END;
  214.  
  215. END   (* DumbTrm *).